﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using 简单三层架构.DBUtility;
using 简单三层架构.IDAL;
using 简单三层架构.Model;

namespace 简单三层架构.DAL
{
    public class Inventory : IInventory
    {
        private const string SQL_TAKE_INVENTORY = "UPDATE Inventory SET Quantity = Quantity - ";

        public void TakeStock(IList<LineItemInfo> lineItems)
        {
            using (SqlConnection connection = SqlHelper.GetConnection())
            {
                foreach (LineItemInfo lineItem in lineItems)
                {
                    StringBuilder builder = new StringBuilder();
                    string commandText =
                        builder.Append(SQL_TAKE_INVENTORY).Append(lineItem.Quantity.ToString()).Append(
                            " WHERE itemId = ").Append(lineItem.ItemId).ToString();
                    SqlHelper.ExecuteNonQuerySqlCommand(commandText, connection);
                }
            }
        }
    }
}